home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Belgian Amiga Club - ADF Collection
/
BS1 part 41.zip
/
BS1 part 41
/
Coder v1.2.2.adf
/
code
/
chiffre.mod
< prev
next >
Wrap
Text File
|
2000-01-02
|
2KB
|
90 lines
IMPLEMENTATION MODULE Chiffre;
FROM SYSTEM IMPORT SHIFT,LONGSET;
FROM RndNum IMPORT PutSeed,GetSeed,RND;
TYPE multi=RECORD
CASE :BOOLEAN OF
TRUE: i:LONGCARD |
FALSE: s:LONGSET
END
END;
VAR seed1,seed2,seed3,seed4:LONGCARD;
PROCEDURE Xor(a,b:LONGCARD):LONGCARD;
VAR a1,b1:multi;
i:INTEGER;
BEGIN
a1.i:=a; b1.i:=b;
FOR i:=0 TO 31 DO
IF ((i IN a1.s)=(i IN b1.s)) & (i IN a1.s) THEN EXCL(a1.s,i) END
END;
RETURN a1.i
END Xor;
PROCEDURE CPrep(VAR key:ARRAY OF CHAR);
VAR st,x0:LONGCARD;
i:CARDINAL;
BEGIN
st:=0; i:=0; x0:=0;
WHILE (i<=CARDINAL(HIGH(key))) & (key[i]#CHR(0)) DO
x0:=Xor(x0,ORD(key[i]));
IF (key[i]>="A") & (key[i]<="Z") THEN
st:=st+LONGCARD(ORD(key[i])-ORD("A")+1)*(i*55+1)
ELSIF (key[i]>="a") & (key[i]<="z") THEN
st:=st+LONGCARD(ORD(key[i])-ORD("a")+27)*(i*55+1)
ELSE
key[i]:=" "; st:=st+54
END;
i:=i+1
END;
st:=st+i*333H;
seed1:=st; seed2:=SHIFT(x0,18); seed3:=Xor(seed1,seed2); seed4:=seed1+seed2
END CPrep;
PROCEDURE Fac():INTEGER;
VAR a:INTEGER;
PROCEDURE ThisFac(VAR seed:LONGCARD; n:INTEGER):INTEGER;
VAR x:INTEGER;
BEGIN
PutSeed(seed); x:=RND(n); GetSeed(seed);
RETURN x
END ThisFac;
BEGIN
a:=ThisFac(seed1,110)+ThisFac(seed2,44+ThisFac(seed3,55)+ThisFac(seed4,25));
IF (Xor(seed1,Xor(seed2,Xor(seed3,seed4))) MOD 2)=1 THEN a:=-a END;
RETURN a
END Fac;
PROCEDURE CTrans(d:BOOLEAN; VAR c:CHAR);
VAR a:INTEGER;
BEGIN
IF d THEN
a:=ORD(c)+Fac()
ELSE
a:=ORD(c)-Fac()
END;
IF a<0 THEN a:=a+100H ELSIF a>0FFH THEN a:=a-100H END;
c:=CHR(a)
END CTrans;
PROCEDURE CCode(d:BOOLEAN; VAR txt:ARRAY OF CHAR; tlen:LONGCARD);
VAR i:LONGCARD;
a:INTEGER;
BEGIN
FOR i:=0 TO tlen-1 DO
IF d THEN
a:=ORD(txt[i])+Fac()
ELSE
a:=ORD(txt[i])-Fac()
END;
IF a<0 THEN a:=a+100H ELSIF a>0FFH THEN a:=a-100H END;
txt[i]:=CHR(a)
END
END CCode;
END Chiffre.